﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace TestHarness
{
    public class SimpleTestCaseFactory
    {
        public static TestCaseCollection ReadTestCases(string path)
        {
            TestCaseCollection tcc = new TestCaseCollection();
            FileStream fs = new FileStream(path, FileMode.Open);
            StreamReader sr = new StreamReader(fs);
            string line;
            string[] firstSplit;
            string[] secondSplit;
            double[] inputs;
            string testcaseName;
            string testcaseID;
            string expected;


            while((line = sr.ReadLine()) != null)
            {
                firstSplit = line.Split(Settings.FieldDelimitedChar);

                testcaseID = firstSplit[0];
                testcaseName = firstSplit[1];
                expected = firstSplit[3];

                secondSplit = firstSplit[2].Split(Settings.ParasDelimitedChar);

                SimpleTestCase stc = new SimpleTestCase();
                stc.TestCaseID = testcaseID;
                stc.TestCaseName = testcaseName;
                stc.Expected = expected;

                inputs = new double[secondSplit.Length];
                for (int i = 0; i < secondSplit.Length; i++)
                {
                    inputs[i] = Convert.ToDouble(secondSplit[i]);
                }

                stc.Values = inputs;
                tcc.Add(stc);
            }

            return tcc;
        }
    }
}
